home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Financial / Emerald1.0 / Source / CanadianObject.m < prev    next >
Encoding:
Text File  |  1996-03-02  |  5.3 KB  |  162 lines

  1.  
  2. #import "CanadianObject.h"
  3.  
  4. @implementation CanadianObject
  5.  
  6.  
  7. // AWAKEFROMNIB
  8. // This is one of the last methods executed after the nib file is loaded.
  9. // This is the BEST way I know how to initialize an object and jump into
  10. // a method after the nib file was loaded, because you are all the methods
  11. // and variables needed can be used. (Unlike init which is not compeletly
  12. // ready when that message is sent
  13. - awakeFromNib
  14. {
  15.  
  16.     [CalcWindow makeKeyAndOrderFront:NULL];
  17.     [StockPrice selectText:self];
  18.  
  19.         return self;
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26. - Calc:sender
  27. {
  28.  
  29.     //Assign Misc Variables
  30.         char dummyString[20];
  31.         int WhichOne;
  32.  
  33.         
  34.     //Assign CalcWindow Variables
  35.     float stockprice;
  36.         float numberofshares;
  37.         float totalstockprice;
  38.         float totalcommission;
  39.         float total;
  40.     float netamountpershare;
  41.  
  42.     stockprice = [StockPrice floatValue];
  43.     numberofshares = [NumberOfShares floatValue];
  44.  
  45.  
  46.     // Take the value in Stock Price * Number of Shares and display
  47.     // the result in the Total Stock Price textfield
  48.     totalstockprice = [StockPrice floatValue] * [NumberOfShares floatValue];
  49.     sprintf(dummyString, "%.2f", totalstockprice); 
  50.     [TotalStockPrice setStringValue:dummyString];// Display result
  51.  
  52.  
  53. // Figure out the commission rate and then do the calculations
  54.  
  55. // Checks if the stock price is below Stock1 if yes then
  56. // calculates the commission using Comm1
  57. if ([StockPrice floatValue] <= [Stock2 floatValue]) totalcommission = (([StockPrice floatValue] * [NumberOfShares floatValue]) * ([Comm1 floatValue] / 100));
  58.  
  59. // Checks if the stock price is >=Stock3 and <= Stock4 if yes then
  60. // calculates the commission by adding Comm2 and multiplying
  61. // Comm3 by the number of shares
  62. if ([StockPrice floatValue] >= [Stock3 floatValue] && [StockPrice floatValue] <= [Stock4 floatValue]) totalcommission = ([Comm2 floatValue] + ([NumberOfShares floatValue] * [Comm3 floatValue]));
  63.  
  64. // Checks if the stock price is >=Stock5 and <= Stock6 if yes then
  65. // calculates the commission by adding Comm4 and multiplying
  66. // Comm5 by the number of shares
  67. if ([StockPrice floatValue] >= [Stock5 floatValue] && [StockPrice floatValue] <= [Stock6 floatValue]) totalcommission = ([Comm4 floatValue] + ([NumberOfShares floatValue] * [Comm5 floatValue]));
  68.  
  69. // Checks if the stock price is >=Stock7 and <= Stock8 if yes then
  70. // calculates the commission by adding Comm6 and multiplying
  71. // Comm7 by the number of shares
  72. if ([StockPrice floatValue] >= [Stock7 floatValue] && [StockPrice floatValue] <= [Stock8 floatValue]) totalcommission = ([Comm6 floatValue] + ([NumberOfShares floatValue] * [Comm7 floatValue]));
  73.  
  74. // Checks if the stock price is >=Stock9 and <= Stock10 if yes then
  75. // calculates the commission by adding Comm8 and multiplying
  76. // Comm9 by the number of shares
  77. if ([StockPrice floatValue] >= [Stock9 floatValue] && [StockPrice floatValue] <= [Stock10 floatValue]) totalcommission = ([Comm8 floatValue] + ([NumberOfShares floatValue] * [Comm9 floatValue]));
  78.  
  79. // Checks if the stock price is >=Stock11 and <= Stock12 if yes then
  80. // calculates the commission by adding Comm10 and multiplying
  81. // Comm11 by the number of shares
  82. if ([StockPrice floatValue] >= [Stock11 floatValue] && [StockPrice floatValue] <= [Stock12 floatValue]) totalcommission = ([Comm10 floatValue] + ([NumberOfShares floatValue] * [Comm11 floatValue]));
  83.  
  84. // Checks if the stock price is >=Stock13 if yes then
  85. // calculates the commission by adding Comm11 and multiplying
  86. // Comm13 by the number of shares
  87. if ([StockPrice floatValue] >= [Stock13 floatValue]) totalcommission = ([Comm12 floatValue] + ([NumberOfShares floatValue] * [Comm13 floatValue]));
  88.  
  89.  
  90.     // Assign variables
  91.     totalstockprice = [TotalStockPrice floatValue];
  92.  
  93.     // Transactions with principal values less than Principal Value 
  94.         // will be charged a flat fee of FlatFee
  95.         if ([TotalStockPrice floatValue] <= [PrincipalValue floatValue]) totalcommission = [FlatFee floatValue];
  96.  
  97.  
  98.     // Assigns the value of the currently selected radio button
  99.      // using tag as a reference and calculate Net Amount
  100.        WhichOne = [RadioButton selectedTag]; 
  101.     if (WhichOne == 2)  totalcommission = totalcommission -(totalcommission * ([TeleMaxInput floatValue] / 100));
  102.  
  103.     // Assigns the value of the currently selected radio button
  104.      // using tag as a reference
  105.        WhichOne = [BuySellRadio selectedTag]; 
  106.     if (WhichOne == 1)  total = totalstockprice + totalcommission;
  107.     if (WhichOne == 2)  total = totalstockprice - totalcommission;
  108.  
  109.     
  110.     // Display Total Commission 
  111.     // Convert float to a string
  112.     sprintf(dummyString, "%.2f", totalcommission); 
  113.     [TotalCommission setStringValue:dummyString];// Display result
  114.  
  115.     // Display Net Amount
  116.     sprintf(dummyString, "%.2f", total); // Convert float to a string
  117.     [Total setStringValue:dummyString];// Display result
  118.  
  119.     // Calculate Net Amount Per Share
  120.     // Number of Shares / Net Amount = Net Amount per Share
  121.     netamountpershare =  [Total floatValue] / [NumberOfShares floatValue];
  122.     // Display Net Amount per Share
  123.     sprintf(dummyString, "%.2f", netamountpershare);
  124.     [NetAmountPerShare setStringValue:dummyString];// Display result
  125.     [NetAmountPerShare display];
  126.  
  127.  
  128.     [StockPrice selectText:self];
  129.  
  130.  
  131.     return self;
  132. }
  133.  
  134. - DirectTrading:sender
  135. {
  136.     return self;
  137. }
  138.  
  139. - PrintCalc:sender
  140. {
  141.  
  142.     [CalcWindow printPSCode:self];
  143.  
  144.     return self;
  145. }
  146.  
  147. - PrintCommSchedule:sender
  148. {
  149.  
  150.     [CommissionWindow printPSCode:self];
  151.  
  152.     return self;
  153. }
  154.  
  155. - TeleMax:sender
  156. {
  157.     return self;
  158. }
  159.  
  160.  
  161. @end
  162.